package org.zanpu.metadataserver.core.metadata.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.zanpu.metadataserver.core.aop.ServiceDataSource;
import org.zanpu.metadataserver.core.dbmanager.DynamicDataSource;
import org.zanpu.metadataserver.core.metadata.dao.MetadataDao;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by MD on 2016/10/26.
 */


@Service
public class MetadataService {

    @Resource
    private MetadataDao metadataDao;

    @ServiceDataSource("metadatadb")
    public List<Map<String, Object>> query(String sql) {
        return metadataDao.query(sql);
    }

    @ServiceDataSource("metadatadb")
    public List<String> queryTable() {
        return metadataDao.queryTable();
    }

    @ServiceDataSource("metadatadb")
    public List<Map<String, Object>> queryColumns(String table) {
        return metadataDao.queryColumns(table);
    }

    @Transactional
    @ServiceDataSource("metadatadb")
    public int update(String sql) {
        return metadataDao.update(sql);
    }

    @Transactional
    @ServiceDataSource("metadatadb")
    public int delete(String sql) {
        return metadataDao.delete(sql);
    }

    @Transactional
    @ServiceDataSource("metadatadb")
    public int insert(Map<String, Object> map) {
        metadataDao.insert(map);
        return Integer.parseInt(map.get("id").toString());

    }
}
